import java.util.ArrayList;
import java.util.Arrays;

import org.junit.Test;

public class MyTest {
    @Test
    public void test(){
/*         int[][] ranges = {{50,50}};
        int left = 1, right = 1;
        System.out.println(isCovered(ranges, left, right)); */

        dopermute(new ArrayList<Integer>(Arrays.asList(1,2,3)));
    }
    public boolean isCovered(int[][] ranges, int left, int right) {
        int[] diff=new int[52];
        for(int[] range:ranges){
            diff[range[0]-1]++;
            diff[range[1]]--;
        }
        if(left==1&&diff[0]<=0){
            return false;
        }
        for(int i=1;i<right;i++){
            diff[i]+=diff[i-1];
            if(i>=left-1&&diff[i]<=0){
                return false;
            }
        }
        return true;
    }



    ArrayList<Integer> ans1=new ArrayList<Integer>(3);
    List<List<Integer>> ans;
    public List<List<Integer>> permute(int[] nums) {
        ans=new ArrayList<List<Integer>>();
        ArrayList<Integer> arrayList=new ArrayList<Integer>(nums.length);
        for(int i:nums){
            arrayList.add(i);
        }
        dopermute(arrayList);
        return ans;
    }
    private void dopermute(ArrayList<Integer> arrayList){
        if(arrayList.size()<=1){
            //System.out.print(arrayList.get(0)+" ");
            ans1.add(arrayList.get(0));
            //System.out.print(ans1+" ");
            ans.add(ans1);
            ans1.remove(ans1.size()-1);
            return;
        }
        ArrayList<Integer> newArrayList=new ArrayList<Integer>(arrayList);
        for(int i=0;i<arrayList.size();i++){
            //System.out.print(arrayList.get(i));
            ans1.add(arrayList.get(i));
            newArrayList.remove(i);
            dopermute(newArrayList);
            ans1.remove(ans1.size()-1);
            newArrayList=new ArrayList<Integer>(arrayList);
        }
    }
}
